package com.epam.matchers;

import java.util.regex.Matcher;
import java.util.regex.Pattern;

public abstract class AbstractMatcher {

	private int startNext;
	protected String src;

	public AbstractMatcher(String src) {
		this.src=src;
		this.startNext=0;
	}
	
	public String nextStringElement(Pattern pattern) {
		String res = null;
		Matcher matcher = pattern.matcher(src);
		if (matcher.find(startNext)) {
			this.startNext = matcher.end();
			res = matcher.group();
		}
		return res;
	}
	
	public String nextStringElement(Pattern pattern, int startPosition) {
		String res = null;
		Matcher matcher = pattern.matcher(src);
		if (matcher.find(startPosition)) {
			this.startNext = matcher.end();
			res = matcher.group();
		}
		return res;
	}

	public int getStartNext() {
		return startNext;
	}

	public void setStartNext(int startNext) {
		this.startNext = startNext;
	}
}
